home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10115 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.5 KB  |  47 lines

  1. Path: gambier.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Kind of an annoying question...
  5. Date: 15 Mar 1996 09:59:08 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4icb5cINN6pq@gambier.ugrad.cs.ubc.ca>
  8. References: <4hvrio$c4k@lastactionhero.rs.itd.umich.edu> <4iaqd4$l70@cs3.brookes.ac.uk> <m.b.greenwood-1503961312510001@mac007016.shef.ac.uk>
  9. NNTP-Posting-Host: gambier.ugrad.cs.ubc.ca
  10.  
  11. In article <m.b.greenwood-1503961312510001@mac007016.shef.ac.uk>,
  12. Mike Greenwood <m.b.greenwood@sheffield.ac.uk> wrote:
  13.  
  14.  >ALERT ALERT ALERT !!!!
  15.  >
  16.  >Fine if it works, but getch() is _NOT_ ansi standard. Beware UNIX users,
  17.  >it's not as simple as all this. See the UNIX FAQ for a cheat way round
  18.  >this, but I still haven't managed to figure it out the 'proper way'.
  19.  
  20. The curses library of UNIX has a getch() function. You have to set up the
  21. terminal first:
  22.  
  23. #include <curses.h>
  24.  
  25. int main()
  26. {
  27.     int c;
  28.  
  29.     initscr();    /* initialize curses            */
  30.     nonl();        /* unset newline mapping        */        
  31.     cbreak();    /* turn off input line processing    */
  32.     noecho();    /* hmm, what do you think?        */
  33.  
  34.     /* now use getch() for blocking keyboard reads     */
  35.     /* select() for polling                */
  36.  
  37.     c = getch();
  38.  
  39.     endwin();    /* restore the terminal, shut down curses    */
  40. }
  41.  
  42. None of this stuff is part of the C standard, however. The curses library 
  43. supports multiple platforms however, including ones that also have ad-hoc
  44. methods for doing the same thing. 
  45. -- 
  46.  
  47.